from django.db import models

class Channel(models.Model):
    '''
    实体账户表
    不生成数据库表
    无联合主键
    '''
    channelid = models.CharField(db_column='ChannelID', primary_key=True, max_length=31, verbose_name='通道ID')  # Field name made lowercase.
    apitype = models.CharField(db_column='ApiType', max_length=1, verbose_name='外部接口类型',)  # Field name made lowercase.
    terminaltype = models.CharField(db_column='TerminalType', max_length=1, verbose_name='通道类型')  # Field name made lowercase.
    userid = models.CharField(db_column='UserID', max_length=20, verbose_name='交易账号')  # Field name made lowercase.
    password = models.CharField(db_column='Password', max_length=100, verbose_name='登录密码')  # Field name made lowercase.
    addresslist = models.CharField(db_column='AddressList', max_length=255, verbose_name='通道地址列表')  # Field name made lowercase.
    closetimepoint = models.CharField(db_column='CloseTimePoint', max_length=8, verbose_name='收盘时间')  # Field name made lowercase.
    loglevel = models.CharField(db_column='LogLevel', max_length=1, verbose_name='日志级别', default="4")  # Field name made lowercase.
    extendinfo = models.TextField(db_column='ExtendInfo',blank=True, null=True, verbose_name='接口扩展信息')  # Field name made lowercase.
    isactive = models.SmallIntegerField(db_column='IsActive', verbose_name='是否启用',default=0)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_channel'

    def __str__(self):
        return self.channelid

class Customerchannelrel(models.Model):
    '''
    分账户信息表
    不生成数据库表
    联合主键，数据库中需要加上id字段
    '''
    customerid = models.ForeignKey(to="Rbac.Customer", on_delete=models.CASCADE, db_column='CustomerID', max_length=20, verbose_name='用户代码')  # Field name made lowercase.
    tdchannelid = models.ForeignKey(to="Channel", on_delete=models.CASCADE, related_name='channel_tdchannelid', db_column='TDChannelID', blank=True, null=True, verbose_name='交易通道')  # Field name made lowercase.
    mdchannelid = models.ForeignKey(to="Channel", on_delete=models.CASCADE, related_name='channel_mdchannelid', db_column='MDChannelID', blank=True, null=True, verbose_name='行情通道')  # Field name made lowercase.
    accountid = models.CharField(db_column='AccountID', max_length=32, verbose_name='分账号代码', unique=True)  # Field name made lowercase.
    tdapitype = models.CharField(db_column='TDApiType', max_length=32, blank=True, null=True, verbose_name='交易接口类型',)  # Field name made lowercase.
    assetno = models.CharField(db_column='AssetNo', max_length=16, blank=True, null=True, verbose_name='资金账号')  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=16, blank=True, null=True, verbose_name='持仓帐号')  # Field name made lowercase.
    apiaccountid = models.CharField(db_column='APIAccountID', max_length=32, blank=True,null=True,verbose_name='UFX AccountID')  # Field name made lowercase.
    apiinvestorid = models.CharField(db_column='APIInvestorID', max_length=16, blank=True,null=True,verbose_name='UFX 股东代码')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_customerchannelrel'
        unique_together = (('customerid', 'accountid'),)

    # def __str__(self):
    #     return self.accountid

class Rule(models.Model):
    # rule
    '''
    用户策略表
    联合主键和primary_key不可共存
    '''
    ruleid = models.IntegerField(db_column='RuleID',verbose_name='策略代码', unique=True)  # Field name made lowercase.
    rulepath = models.CharField(db_column='RulePath', max_length=256,verbose_name='策略Dll存储位置')  # Field name made lowercase.
    ruleversion = models.CharField(db_column='RuleVersion', max_length=31,verbose_name='策略版本')  # Field name made lowercase.
    rulename = models.CharField(db_column='RuleName', max_length=31,verbose_name='策略名称')  # Field name made lowercase.
    configpath = models.CharField(db_column='ConfigPath', max_length=256,verbose_name='策略配置文件存储位置')  # Field name made lowercase.
    customerid = models.CharField(db_column='CustomerID', max_length=20,verbose_name='用户代码')  # Field name made lowercase.
    isclientloaded = models.SmallIntegerField(db_column='IsClientLoaded', blank=True, default=0, null=True,verbose_name='是否客户端加载',)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_rule'
        unique_together = (('ruleid', 'customerid'),)

class Customerrulerel(models.Model):
    '''
    策略配对表
    '''
    customerid = models.CharField(db_column='CustomerID', max_length=20,verbose_name='用户代码')  # Field name made lowercase.
    ruleid = models.IntegerField(db_column='RuleID',verbose_name='策略ID号')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_customerrulerel'
        unique_together = (('customerid', 'ruleid'),)

class Makemarketpara(models.Model):
    '''
    合约做市参数
    '''
    instrumentid = models.CharField(db_column='InstrumentID', max_length=30, verbose_name='合约代码')  # Field name made lowercase.
    exchangeid = models.CharField(db_column='ExchangeID', max_length=10, verbose_name='交易所代码', )  # Field name made lowercase.
    isinvolved = models.SmallIntegerField(db_column='IsInvolved', verbose_name='是否参与做市', default=0)  # Field name made lowercase.
    buypricespread = models.FloatField(db_column='BuyPriceSpread', verbose_name='买价上浮价差')  # Field name made lowercase.
    sellpricespread = models.FloatField(db_column='SellPriceSpread', verbose_name='卖价下沉价差')  # Field name made lowercase.
    buyvolume = models.BigIntegerField(db_column='BuyVolume', verbose_name='买数量')  # Field name made lowercase.
    sellvolume = models.BigIntegerField(db_column='SellVolume', verbose_name='卖数量')  # Field name made lowercase.
    minbuyvolume = models.BigIntegerField(db_column='MinBuyVolume', verbose_name='最低买数量')  # Field name made lowercase.
    minsellvolume = models.BigIntegerField(db_column='MinSellVolume', verbose_name='最低卖数量')  # Field name made lowercase.
    maxspread = models.FloatField(db_column='MaxSpread', verbose_name='最大买卖价差')  # Field name made lowercase.
    # accountid = models.ForeignKey(to="Customerchannelrel", db_column='AccountID', max_length=32,verbose_name='分账号代码', on_delete=models.CASCADE, to_field=('accountid'))  # Field name made lowercase.
    # accountid = models.ForeignKey(to='Customerchannelrel',db_column='AccountID',max_length=32,verbose_name='分账号代码',on_delete=models.CASCADE,to_field=("accountid"),related_name='c_accountid')
    accountid = models.ForeignKey(db_column='AccountID',on_delete=models.CASCADE,to='Customerchannelrel',related_name='c_aid',to_field=('accountid'))
    combino = models.CharField(db_column='CombiNo', max_length=20, verbose_name='持仓帐号')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_makemarketpara'
        unique_together = (('instrumentid', 'combino'),)

class Makemarketstatus(models.Model):
    '''
    合约做市状态
    不需要前台页面，TMakemarketpara(合约做市参数)
    新增一条记录的时候，需要在MakeMarketStatus表中同时新增一条记录，
    遵守以下规则：
    InstrumentID / AccountID / CombiNo 和 MakeMarketPara记录的相同，其它的都为0
    '''
    instrumentid = models.CharField(db_column='InstrumentID', max_length=30, verbose_name='合约代码')  # Field name made lowercase.
    status = models.SmallIntegerField(db_column='status', verbose_name='是否正在做市', )
    buystatus = models.CharField(db_column='BuyStatus', max_length=1, verbose_name='买单状态')  # Field name made lowercase.
    sellstatus = models.CharField(db_column='SellStatus', max_length=1, verbose_name='卖单状态')  # Field name made lowercase.
    lastrectime = models.IntegerField(db_column='LastRecTime', verbose_name='上次有效时间点')  # Field name made lowercase.
    markettimeday = models.IntegerField(db_column='MarketTimeDay', verbose_name='当天有效做市时间')  # Field name made lowercase.
    markettimemonth = models.IntegerField(db_column='MarketTimeMonth', verbose_name='当月有效做市时间')  # Field name made lowercase.
    tradevolumeday = models.BigIntegerField(db_column='TradeVolumeDay', verbose_name='当日做市交易量')  # Field name made lowercase.
    tradevolumemonth = models.BigIntegerField(db_column='TradeVolumeMonth', verbose_name='当月做市交易量')  # Field name made lowercase.
    lastupddate = models.CharField(db_column='LastUpdDate', max_length=19, verbose_name='上次更新日期')  # Field name made lowercase.
    accountid = models.CharField(db_column='AccountID', max_length=32, verbose_name='分账号代码')  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=20, verbose_name='持仓帐号')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_makemarketstatus'
        unique_together = (('instrumentid', 'combino'),)

class Positionlimit(models.Model):
    # positionlimit
    '''
    策略限仓
    '''
    ruleid = models.IntegerField(db_column='RuleID', blank=True, null=False, verbose_name='策略ID号')  # Field name made lowercase.
    direction = models.CharField(db_column='Direction',  max_length=1, verbose_name='买入卖出', null=False)  # Field name made lowercase.
    volumelimit = models.BigIntegerField(db_column='VolumeLimit', blank=True, null=False, verbose_name='限制额度')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_positionlimit'
        unique_together=(('ruleid', 'direction'),)

class Macaddress(models.Model):
    # tmacaddress
    '''
    MAC地址白名单
    '''
    customerid = models.CharField(db_column='CustomerID', max_length=20, blank=True, null=True,
                                  verbose_name='CustomerID标识')  # Field name made lowercase.
    description = models.CharField(db_column='Description', max_length=400, blank=True, null=True,
                                   verbose_name='描述')  # Field name made lowercase.
    macaddress = models.CharField(db_column='MacAddress', max_length=20,
                                  verbose_name='Mac地址')  # Field name made lowercase.
    isactive = models.SmallIntegerField(db_column="IsActive",  default=0, verbose_name="是否启用")

    class Meta:
        managed = False
        db_table = 't_macaddress'
        unique_together = (('macaddress'),)

class Dbinfo(models.Model):
    '''
    数据库信息维护表
    不生成表

    '''
    dbtype = models.CharField(db_column='DBType', primary_key=True, max_length=20, verbose_name='数据库名')  # Field name made lowercase.
    dbconnstr = models.CharField(db_column='DBConnStr', max_length=30, verbose_name='数据库地址')  # Field name made lowercase.
    dbusername = models.CharField(db_column='DBUserName', max_length=20, verbose_name='数据库用户名')  # Field name made lowercase.
    dbpassword = models.CharField(db_column='DBPassword', max_length=100, verbose_name='密码')  # Field name made lowercase.
    createtime = models.CharField(db_column='CreateTime', max_length=19, blank=True, null=True, verbose_name='创建时间')  # Field name made lowercase.
    updatetime = models.CharField(db_column='UpdateTime', max_length=19, blank=True, null=True, verbose_name='更新时间')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_dbinfo'

class Ruleorder(models.Model):
    frontid = models.IntegerField(db_column='FrontID')  # Field name made lowercase.
    sessionid = models.IntegerField(db_column='SessionID')  # Field name made lowercase.
    accountid = models.CharField(db_column='AccountID', max_length=32)  # Field name made lowercase.
    assetno = models.CharField(db_column='AssetNo', max_length=16)  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=20)  # Field name made lowercase.
    exchangeid = models.CharField(db_column='ExchangeID', max_length=10)  # Field name made lowercase.
    commoditytype = models.CharField(db_column='CommodityType', max_length=1, blank=True, null=True)  # Field name made lowercase.
    instrumentid = models.CharField(db_column='InstrumentID', max_length=30)  # Field name made lowercase.
    instrumentname = models.CharField(db_column='InstrumentName', max_length=128, blank=True, null=True)  # Field name made lowercase.
    orderpricetype = models.CharField(db_column='OrderPriceType', max_length=1)  # Field name made lowercase.
    direction = models.CharField(db_column='Direction', max_length=1, blank=True, null=True)  # Field name made lowercase.
    offsetflag = models.CharField(db_column='OffsetFlag', max_length=1, blank=True, null=True)  # Field name made lowercase.
    hedgeflag = models.CharField(db_column='HedgeFlag', max_length=1, blank=True, null=True)  # Field name made lowercase.
    price = models.DecimalField(db_column='Price', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    volume = models.BigIntegerField(db_column='Volume')  # Field name made lowercase.
    timecondition = models.CharField(db_column='TimeCondition', max_length=1, blank=True, null=True)  # Field name made lowercase.
    ruleid = models.IntegerField(db_column='RuleID')  # Field name made lowercase.
    customerid = models.CharField(db_column='CustomerID', max_length=20)  # Field name made lowercase.
    bilateralid = models.CharField(db_column='BilateralID', max_length=12, blank=True, null=True)  # Field name made lowercase.
    purchaseway = models.CharField(db_column='PurchaseWay', max_length=1, blank=True, null=True)  # Field name made lowercase.
    text = models.CharField(db_column='Text', max_length=200, blank=True, null=True)  # Field name made lowercase.
    ytm = models.DecimalField(db_column='YTM', max_digits=10, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    strikeyeild = models.DecimalField(db_column='StrikeYeild', max_digits=10, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    quotetype = models.SmallIntegerField(db_column='QuoteType')  # Field name made lowercase.
    maxfloor = models.BigIntegerField(db_column='MaxFloor', blank=True, null=True)  # Field name made lowercase.
    minticksize = models.BigIntegerField(db_column='MinTickSize', blank=True, null=True)  # Field name made lowercase.
    legsettltype = models.SmallIntegerField(db_column='LegSettlType', blank=True, null=True)  # Field name made lowercase.
    matchtype = models.SmallIntegerField(db_column='MatchType', blank=True, null=True)  # Field name made lowercase.
    deliverytype = models.SmallIntegerField(db_column='DeliveryType', blank=True, null=True)  # Field name made lowercase.
    clearingmethod = models.SmallIntegerField(db_column='ClearingMethod', blank=True, null=True)  # Field name made lowercase.
    quoteid = models.CharField(db_column='QuoteID', max_length=30, blank=True, null=True)  # Field name made lowercase.
    validuntiltime = models.CharField(db_column='ValidUntilTime', max_length=24, blank=True, null=True)  # Field name made lowercase.
    mdentrytime = models.CharField(db_column='MDEntryTime', max_length=24, blank=True, null=True)  # Field name made lowercase.
    clordid = models.CharField(db_column='ClOrdID', max_length=30, blank=True, null=True)  # Field name made lowercase.
    routingtype = models.SmallIntegerField(db_column='RoutingType', blank=True, null=True)  # Field name made lowercase.
    marketindicator = models.SmallIntegerField(db_column='MarketIndicator', blank=True, null=True)  # Field name made lowercase.
    realtimeundertakeflag = models.SmallIntegerField(db_column='RealTimeUndertakeFlag', blank=True, null=True)  # Field name made lowercase.
    subjectpartytype = models.SmallIntegerField(db_column='SubjectPartyType', blank=True, null=True)  # Field name made lowercase.
    orderinnerid = models.CharField(db_column='OrderInnerID', primary_key=True, max_length=12)  # Field name made lowercase.
    ordersysid = models.CharField(db_column='OrderSysID', max_length=20, blank=True, null=True)  # Field name made lowercase.
    inserttime = models.CharField(db_column='InsertTime', max_length=8)  # Field name made lowercase.
    tradingday = models.CharField(db_column='TradingDay', max_length=8)  # Field name made lowercase.
    tradeprice = models.DecimalField(db_column='TradePrice', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    volumetraded = models.BigIntegerField(db_column='VolumeTraded')  # Field name made lowercase.
    volumetotal = models.BigIntegerField(db_column='VolumeTotal')  # Field name made lowercase.
    ordersubmitstatus = models.CharField(db_column='OrderSubmitStatus', max_length=1)  # Field name made lowercase.
    orderstatus = models.CharField(db_column='OrderStatus', max_length=1)  # Field name made lowercase.
    insertdate = models.CharField(db_column='InsertDate', max_length=8, blank=True, null=True)  # Field name made lowercase.
    updatedate = models.CharField(db_column='UpdateDate', max_length=8, blank=True, null=True)  # Field name made lowercase.
    updatetime = models.CharField(db_column='UpdateTime', max_length=8, blank=True, null=True)  # Field name made lowercase.
    canceltime = models.CharField(db_column='CancelTime', max_length=8, blank=True, null=True)  # Field name made lowercase.
    errorcode = models.IntegerField(db_column='ErrorCode')  # Field name made lowercase.
    statusmsg = models.CharField(db_column='StatusMsg', max_length=200, blank=True, null=True)  # Field name made lowercase.
    settlementid = models.IntegerField(db_column='SettlementID')  # Field name made lowercase.
    ordersource = models.CharField(db_column='OrderSource', max_length=1)  # Field name made lowercase.
    clientid = models.CharField(db_column='ClientID', max_length=22, blank=True, null=True)  # Field name made lowercase.
    traderid = models.CharField(db_column='TraderID', max_length=20, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_ruleorder'
        unique_together = (('orderinnerid', 'tradingday'))


class Ruleposition(models.Model):
    tradingday = models.CharField(db_column='TradingDay', primary_key=True, max_length=8)  # Field name made lowercase.
    exchangeid = models.CharField(db_column='ExchangeID', max_length=10)  # Field name made lowercase.
    commodityid = models.CharField(db_column='CommodityID', max_length=10, blank=True, null=True)  # Field name made lowercase.
    exchangeinstid = models.CharField(db_column='ExchangeInstID', max_length=30, blank=True, null=True)  # Field name made lowercase.
    instrumentid = models.CharField(db_column='InstrumentID', max_length=30)  # Field name made lowercase.
    posidirection = models.CharField(db_column='PosiDirection', max_length=1)  # Field name made lowercase.
    hedgeflag = models.CharField(db_column='HedgeFlag', max_length=1)  # Field name made lowercase.
    positionprofitbydate = models.DecimalField(db_column='PositionProfitByDate', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    positionprofitbytrade = models.DecimalField(db_column='PositionProfitByTrade', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    closeprofitbydate = models.DecimalField(db_column='CloseProfitByDate', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    closeprofitbytrade = models.DecimalField(db_column='CloseProfitByTrade', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    positiondate = models.CharField(db_column='PositionDate', max_length=1)  # Field name made lowercase.
    ydposition = models.BigIntegerField(db_column='YdPosition')  # Field name made lowercase.
    position = models.BigIntegerField(db_column='Position')  # Field name made lowercase.
    todayposition = models.BigIntegerField(db_column='TodayPosition')  # Field name made lowercase.
    frozenposition = models.BigIntegerField(db_column='FrozenPosition')  # Field name made lowercase.
    frozenamount = models.DecimalField(db_column='FrozenAmount', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    openvolume = models.BigIntegerField(db_column='OpenVolume')  # Field name made lowercase.
    closevolume = models.BigIntegerField(db_column='CloseVolume')  # Field name made lowercase.
    openamount = models.DecimalField(db_column='OpenAmount', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    closeamount = models.DecimalField(db_column='CloseAmount', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    positioncost = models.DecimalField(db_column='PositionCost', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    opencost = models.DecimalField(db_column='OpenCost', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    premargin = models.DecimalField(db_column='PreMargin', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    usemargin = models.DecimalField(db_column='UseMargin', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    frozenmargin = models.DecimalField(db_column='FrozenMargin', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    frozencash = models.DecimalField(db_column='FrozenCash', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    frozencommission = models.DecimalField(db_column='FrozenCommission', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    adjust = models.DecimalField(db_column='Adjust', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    tradecommission = models.DecimalField(db_column='TradeCommission', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    presettlementprice = models.DecimalField(db_column='PreSettlementPrice', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    ruleid = models.IntegerField(db_column='RuleID')  # Field name made lowercase.
    customerid = models.CharField(db_column='CustomerID', max_length=20, blank=True, null=True)  # Field name made lowercase.
    traderid = models.CharField(db_column='TraderID', max_length=20, blank=True, null=True)  # Field name made lowercase.
    assetno = models.CharField(db_column='AssetNo', max_length=16)  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=20)  # Field name made lowercase.
    longfrozen = models.BigIntegerField(db_column='LongFrozen')  # Field name made lowercase.
    shortfrozen = models.BigIntegerField(db_column='ShortFrozen')  # Field name made lowercase.
    longfrozenamount = models.DecimalField(db_column='LongFrozenAmount', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    shortfrozenamount = models.DecimalField(db_column='ShortFrozenAmount', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    marginratebyvolume = models.DecimalField(db_column='MarginRateByVolume', max_digits=10, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    marginratebymoney = models.DecimalField(db_column='MarginRateByMoney', max_digits=10, decimal_places=4, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_ruleposition'
        unique_together = (('tradingday', 'instrumentid', 'posidirection', 'hedgeflag', 'positiondate', 'combino'),)


class Ruletrade(models.Model):
    exchangeid = models.CharField(db_column='ExchangeID', max_length=10)  # Field name made lowercase.
    tradingday = models.CharField(db_column='TradingDay', primary_key=True, max_length=8)  # Field name made lowercase.
    tradeid = models.CharField(db_column='TradeID', max_length=70)  # Field name made lowercase.
    ordersysid = models.CharField(db_column='OrderSysID', max_length=20)  # Field name made lowercase.
    orderinnerid = models.CharField(db_column='OrderInnerID', max_length=12)  # Field name made lowercase.
    commodityid = models.CharField(db_column='CommodityID', max_length=10, blank=True, null=True)  # Field name made lowercase.
    instrumentid = models.CharField(db_column='InstrumentID', max_length=30)  # Field name made lowercase.
    userid = models.CharField(db_column='UserID', max_length=20)  # Field name made lowercase.
    direction = models.CharField(db_column='Direction', max_length=1)  # Field name made lowercase.
    offsetflag = models.CharField(db_column='OffsetFlag', max_length=1, blank=True, null=True)  # Field name made lowercase.
    hedgeflag = models.CharField(db_column='HedgeFlag', max_length=1, blank=True, null=True)  # Field name made lowercase.
    orderprice = models.DecimalField(db_column='OrderPrice', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    tradeprice = models.DecimalField(db_column='TradePrice', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    ytm = models.DecimalField(db_column='YTM', max_digits=10, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    volumetraded = models.BigIntegerField(db_column='VolumeTraded')  # Field name made lowercase.
    tradedate = models.CharField(db_column='TradeDate', max_length=8)  # Field name made lowercase.
    tradetime = models.CharField(db_column='TradeTime', max_length=8)  # Field name made lowercase.
    tradefee = models.DecimalField(db_column='TradeFee', max_digits=19, decimal_places=3, blank=True, null=True)  # Field name made lowercase.
    currencyid = models.CharField(db_column='CurrencyID', max_length=10, blank=True, null=True)  # Field name made lowercase.
    manualfee = models.CharField(db_column='ManualFee', max_length=1, blank=True, null=True)  # Field name made lowercase.
    deleted = models.CharField(db_column='Deleted', max_length=1, blank=True, null=True)  # Field name made lowercase.
    coverprice = models.DecimalField(db_column='CoverPrice', max_digits=12, decimal_places=4, blank=True, null=True)  # Field name made lowercase.
    exchangeinstid = models.CharField(db_column='ExchangeInstID', max_length=30, blank=True, null=True)  # Field name made lowercase.
    brokerid = models.CharField(db_column='BrokerID', max_length=10, blank=True, null=True)  # Field name made lowercase.
    investorid = models.CharField(db_column='InvestorID', max_length=20, blank=True, null=True)  # Field name made lowercase.
    ruleid = models.IntegerField(db_column='RuleID', blank=True, null=True)  # Field name made lowercase.
    customerid = models.CharField(db_column='CustomerID', max_length=20)  # Field name made lowercase.
    accountid = models.CharField(db_column='AccountID', max_length=32)  # Field name made lowercase.
    commoditytype = models.CharField(db_column='CommodityType', max_length=1)  # Field name made lowercase.
    assetno = models.CharField(db_column='AssetNo', max_length=16)  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=20)  # Field name made lowercase.
    bilateralid = models.CharField(db_column='BilateralID', max_length=12, blank=True, null=True)  # Field name made lowercase.
    clientid = models.CharField(db_column='ClientID', max_length=22, blank=True, null=True)  # Field name made lowercase.
    traderid = models.CharField(db_column='TraderID', max_length=20, blank=True, null=True)  # Field name made lowercase.
    quotetype = models.SmallIntegerField(db_column='QuoteType', blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_ruletrade'
        unique_together = (('tradingday', 'tradeid', 'instrumentid', 'direction'),)


class Selftradechannel(models.Model):
    channelid = models.CharField(db_column='ChannelID', primary_key=True, max_length=31)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_selftradechannel'

class Accountmapping(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True)  # Field name made lowercase.
    combino = models.CharField(db_column='CombiNo', max_length=40)  # Field name made lowercase.
    combiname = models.CharField(db_column='CombiName', max_length=50)  # Field name made lowercase.
    accid = models.CharField(db_column='ACCID', max_length=40)  # Field name made lowercase.
    accname = models.CharField(db_column='ACCName', max_length=50)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 't_accountmapping'
        unique_together = (('id', 'combino', 'accid'),)


class Calendar(models.Model):
    tradingday = models.CharField(primary_key=True, max_length=10)

    class Meta:
        managed = False
        db_table = 't_calendar'


class Tradetime(models.Model):
    id = models.AutoField(db_column='ID', primary_key=True)  # Field name made lowercase.
    start_time = models.CharField(max_length=8)
    stop_time = models.CharField(max_length=8)
    unique_together = (('id','start_time', 'start_time'),)

    class Meta:
        managed = False
        db_table = 't_tradetime'
